<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
</head>
<body>
    <div ng-app="myapp">
 
        <div ng-controller="firstController">
            <input type="text" value="" ng-model="name"/>
         		   改变次数:{{count}}-{{name}}
        </div>
    </div>
	<script type="text/javascript" src="js/angular.js" ></script>
	<script>
		var myapp=angular.module("myapp",[]);
		myapp.controller('firstController',function($scope){
			 $scope.name='张三';
   			 $scope.count=0;
    // 监听一个model 当一个model每次改变时 都会触发第2个函数
    $scope.$watch('name',function(newValue,oldValue){
 
        ++$scope.count;
        if($scope.count > 30){
            $scope.name = '已经大于30次了';
        }
    })
		})
	</script>
</body>
</html>